package user.ucm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

public class UCGetAirline{
    private Vector v = new Vector();

    public UCGetAirline() {}

    public Vector run(){
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/cp3120?user=root&password=root");
            con.setCatalog("cp3120");

            Statement statement = con.createStatement();
            String search = "SELECT * FROM airinfo;";

            ResultSet test = statement.executeQuery(search);
            if (!test.first()) {
                return null;
            } else {
                test.beforeFirst();
                while(test.next()){
                    v.add(test.getString("AirlineName"));
                }
                return v;
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

}
